package com.fjut.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjut.model.live.LiveCourse;
import com.fjut.model.live.LiveCourseAccount;
import com.fjut.result.Result;
import com.fjut.service.LiveCourseAccountService;
import com.fjut.service.LiveCourseService;
import com.fjut.vo.live.LiveCourseConfigVo;
import com.fjut.vo.live.LiveCourseFormVo;
import com.fjut.vo.live.LiveCourseVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 直播课程表 前端控制器
 * </p>
 *
 * @author DengTianxun
 * @since 2023-03-20
 */
@RestController
@RequestMapping("/fjut/live/liveCourse")
public class LiveCourseController {
    @Autowired
    private LiveCourseService liveCourseService;

    @Autowired
    private LiveCourseAccountService liveCourseAccountService;

    @ApiOperation("获取最近的直播")
    @GetMapping("findLatelyList")
    public Result findLatelyList() {
        return Result.success(liveCourseService.getLatelyList());
    }

    @ApiOperation("修改直播配置")
    @PostMapping("updateConfig")
    public Result updateConfig(@RequestBody LiveCourseConfigVo liveCourseConfigVo) {
        return Result.success(liveCourseService.updateConfig(liveCourseConfigVo));
    }

    @ApiOperation("获取直播账号信息")
    @GetMapping("getLiveCourseAccount/{id}")
    public Result getLiveCourseAccount(@PathVariable Long id) {
        return Result.success(liveCourseAccountService.getLiveCourseAccountCourseId(id));
    }

    @ApiOperation("获取直播配置信息")
    @GetMapping("getCourseConfigById/{id}")
    public Result getCourseConfig(@PathVariable Long id) {
        return Result.success(liveCourseService.getCourseConfig(id));
    }

    @ApiOperation("id查询直播课程基本信息")
    @GetMapping("getLiveCourseById/{id}")
    public Result get(@PathVariable Long id) {
        return Result.success(liveCourseService.getById(id));
    }

    @ApiOperation("id查询直播课程基本信息和描述信息")
    @GetMapping("getLiveCourseInfoById/{id}")
    public Result getInfo(@PathVariable Long id) {
        return Result.success(liveCourseService.getLiveCourseVo(id));
    }


    @ApiOperation("更新直播课程")
    @PostMapping("updateLiveCourse")
    public Result updateLiveCourse(@RequestBody LiveCourseFormVo liveCourseFormVo) {
        return Result.success(liveCourseService.updateLive(liveCourseFormVo));
    }

    @ApiOperation("根据ID删除课程")
    @DeleteMapping("removeLive/{id}")
    public Result remove(@PathVariable Long id) {
        return Result.success(liveCourseService.removeLive(id));
    }

    @ApiOperation("批量删除课程")
    @DeleteMapping("removeLiveList")
    public Result removeLiveList(@RequestBody List<Long> ids) {
        return Result.success(liveCourseService.removeByIds(ids));
    }

    @ApiOperation("直播课程添加")
    @PostMapping("saveLive")
    public Result saveLive(@RequestBody LiveCourseFormVo liveCourseFormVo) {
        return Result.success(liveCourseService.saveLive(liveCourseFormVo));
    }

    @ApiOperation("直播课程列表")
    @GetMapping("getPageLiveList/{page}/{limit}")
    public Result list(@PathVariable Long page,@PathVariable Long limit) {
        Page<LiveCourse> pageParam = new Page<>(page,limit);
        return Result.success(liveCourseService.selectPage(pageParam));
    }
}

